//
//  MyBaseViewController.m
//  JiFengDaRen
//
//  Created by zhuchao on 16/9/14.
//  Copyright © 2016年 SH_iOS. All rights reserved.
//

#import "MyBaseViewController.h"
#import "UIButton+EnlargeTouchArea.h"
//#import "VHLNavigation.h"

@interface MyBaseViewController ()

@end

@implementation MyBaseViewController
- (UIStatusBarStyle)preferredStatusBarStyle{
    
    return  UIStatusBarStyleDefault;
}
- (BOOL)shouldAutorotate{
    return NO;
}

-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self createNavigationBar];
    self.navigationController.navigationBar.hidden = NO;
    self.navigationItem.title = self.title;
    

}


- (void)createNavigationBar{
    
    self.view.backgroundColor = KBASEBGCOLOR;
    _leftBackBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _leftBackBtn.frame = CGRectMake(0, 0,60, 39);
    [_leftBackBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [_leftBackBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 25)];
    _leftBackBtn.titleLabel.font =  KSHSystemFont(17);
    [_leftBackBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    if (@available(iOS 11.0, *)){//表示只在ios11以上的版本执行
        _leftBackBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    }
    [_leftBackBtn setEnlargeEdgeWithTop:20 right:40 bottom:10 left:20];

    [_leftBackBtn addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"ffffff"];

    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#333333"],NSFontAttributeName:[UIFont boldSystemFontOfSize:17]};
    
    UIBarButtonItem *leftItem  = [[UIBarButtonItem alloc]initWithCustomView:_leftBackBtn];
    
    UIBarButtonItem *fixedButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    
    fixedButton.width =  -14;
    
    self.navigationItem.leftBarButtonItems = @[fixedButton,leftItem];
    
    self.navigationLine = [[UIView alloc]initWithFrame:CGRectMake(0,43.5, KScreenWidth, 0.5)];
    self.navigationLine.backgroundColor = KLINECOLOR;
    [self.navigationController.navigationBar addSubview:self.navigationLine];
    
   

}

//调整navigationBar上控件的位置
-(void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    if (@available(iOS 11.0, *)){
    [_leftBackBtn setFrame:CGRectMake(-14, 0,60, 39)];
    }
   
}

- (void)back:(UIBarButtonItem *)item{
    
    if ([self.navigationController respondsToSelector:@selector(popViewControllerAnimated:)]) {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

#pragma mark -- 查找出导航栏的分割线
-(UIImageView *)findHairlineImageViewUnder:(UIView *)view {
    [[UINavigationBar appearance] setShadowImage:nil];
    if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
        return (UIImageView *)view;
    }
    for (UIView *subview in view.subviews) {
        UIImageView *imageView = [self findHairlineImageViewUnder:subview];
        if (imageView) {
            return imageView;
        }
    }
    return nil;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
